package mynet

type userRoom struct {
	users     map[string]IConnection
	roomOwner string
}

func (this *userRoom) GetOtherUser(usernumber string) []IConnection {
	users := make([]IConnection, 0, 4)
	for _usernumber, user := range this.users {
		if _usernumber != usernumber {
			users = append(users, user)
		}
	}
	return users
}

func (this *userRoom) Join(usernumber string, user IConnection) {
	if len(this.users) >= 4 {
		return
	}
	this.users[usernumber] = user
}

func (this *userRoom) Del(usernumber string) {
	delete(this.users, usernumber)
}

func (this *userRoom) CheckIsFull() bool {
	if len(this.users) >= 4 {
		return true
	}

	return false
}

func (this *userRoom) GetAllUserNumber() []string {
	usernumbers := make([]string, 0, len(this.users))
	for user, _ := range this.users {
		usernumbers = append(usernumbers, user)
	}

	return usernumbers
}

func (this *userRoom) GetRoomOwner() string {
	return this.roomOwner
}

func GetNewUserRoom(usernumber string) IUserRoom {
	return &userRoom{
		users:     make(map[string]IConnection),
		roomOwner: usernumber,
	}
}
